﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataAccess;
using DAO;
using System.Data;
namespace BUL
{
    public class QualificationBUL
    {

        ConnectDatabase cd = new ConnectDatabase();
        public DataTable load(String id)
        {
            String sql = "select qualification.type,qualification.date,qualification.institution from qualification,staff where qualification.idQualification=staff.idQualification and staff.idStaff='" + id + "'";
            return cd.ExcuteQuery(sql);
        }
        public Boolean insert(QualificationDAO p)
        {
            String sql = @"insert into qualification (type, date, institution) values(@type,@date,@institution)";
            int count = 3;
            String[] name = new String[count];
            object[] value = new object[count];
            name[0] = "@type";
            name[1] = "@date";
            name[2] = "@institution";
            value[0] = p.Type;
            value[1] = p.Date;
            value[2] = p.Institution;
            return cd.ExcuteNonQuery(sql, name, value, count);
        }
        public Boolean update(QualificationDAO p)
        {
            String sql = @"update qualification set type=@type, date=@date, institution=@institution where idQualification=@id";
            int count = 4;
            String[] name = new String[count];
            object[] value = new object[count];
            name[0] = "@type";
            name[1] = "@date";
            name[2] = "@institution";
            name[3] = "@id";
            value[0] = p.Type;
            value[1] = p.Date;
            value[2] = p.Institution;
            value[3] = p.IdQualification;
            return cd.ExcuteNonQuery(sql, name, value, count);
        }
        public Boolean delete(String id)
        {
            String sql = @"delete from qualification where idQualification = '" + id + "'";
            return cd.ExcuteNonQuery(sql);
        }
        public int getIdLast() {
            String sql = @"select MAX(idQualification) from qualification";
            DataTable dt = cd.ExcuteQuery(sql);
            return Int32.Parse(dt.Rows[0][0].ToString());
        }
        public int getIdByStaff(String id) {
            String sql = @"select idQualification from staff where idStaff='"+id+"'";
            DataTable dt = cd.ExcuteQuery(sql);
            return Int32.Parse(dt.Rows[0][0].ToString());
        }
    }
}
